package com.hcjy.entity.resp;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

/**
 * 通用分页查询数据封装类
 * @author Guqier
 * @version 1.0
 * @date 2023/7/3 21:23
 */
@Data
@NoArgsConstructor
public class PageR<T> {

    private List<T> records;// 当前页数据

    private Long total;// 总数

    private Long size;// 当前页大小

    private Long current;// 当前页数

    public PageR(Page<T> page) {
        this.total = page.getTotal();
        this.size = page.getSize();
        this.current = page.getCurrent();
    }

    public PageR(Long total,Long size,Long current,List<T> records){
        this.total = total;
        this.size = size;
        this.current = current;
        this.records = records;
    }

    public static <K,R> PageR<R> of(Page<K> page, List<R> records) {
        return new PageR<>(page.getTotal(),page.getSize(),page.getCurrent(),records);
    }

    public static <R> PageR<R> empty(Page<R> page) {
        return new PageR<>(0L,page.getSize(),page.getCurrent(),null);
    }
}
